package com.songdehuai.supermarket.result;


import android.os.Parcel;
import android.os.Parcelable;

/**
 * 描述：
 *
 * @author songdehuai
 * @ClassName: com.songdehuai.supermarket.result.ResultBean
 * @date 2018/6/26 上午9:20
 */
public class ResultParcelable<T extends Parcelable> implements Parcelable {

    private int code;
    private String message;
    private T result;


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.code);
        dest.writeString(this.message);
        dest.writeParcelable(this.result, flags);
    }

    public ResultParcelable() {
    }

    protected ResultParcelable(Parcel in) {
        this.code = in.readInt();
        this.message = in.readString();
        String dataName = in.readString();
        try {
            this.result = in.readParcelable(Class.forName(dataName).getClassLoader());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static final Creator<ResultParcelable> CREATOR = new Creator<ResultParcelable>() {
        @Override
        public ResultParcelable createFromParcel(Parcel source) {
            return new ResultParcelable(source);
        }

        @Override
        public ResultParcelable[] newArray(int size) {
            return new ResultParcelable[size];
        }
    };
}
